import request from '@/utils/request'

// 获取订单采购信息列表
export function Get(args) {
  return request({
    url: `/crm/api/crmorderpurchase/${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

// 创建订单采购信息
export function Post(data) {
  return request({
    url: '/crm/api/crmorderpurchase/create/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 更新订单采购信息
export function Put(id, data) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: data
  })
}

// 删除订单采购信息
export function Delete(id) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/delete/`,
    method: 'delete'
  })
}

// 获取订单采购信息详情
export function GetDetail(id) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/detail/`,
    method: 'get'
  })
}

// 添加采购备注
export function AddRemark(id, data) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/remarks/`,
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 获取采购备注历史
export function GetRemarks(id, args) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/remarks/list/${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

// 获取订单和供应商选项
export function GetOptions() {
  return request({
    url: '/crm/api/crmorderpurchase/options/',
    method: 'get'
  })
}

// 获取采购统计信息
export function GetStatistics() {
  return request({
    url: '/crm/api/crmorderpurchase/statistics/',
    method: 'get'
  })
}

// 批量更新状态
export function BatchUpdateStatus(data) {
  return request({
    url: '/crm/api/crmorderpurchase/batch_status/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 搜索订单
export function SearchOrders(query) {
  return request({
    url: `/crm/api/crmorderpurchase/search_orders/?q=${encodeURIComponent(query)}`,
    method: 'get'
  })
}

// 搜索供应商
export function SearchSuppliers(query) {
  return request({
    url: `/crm/api/crmorderpurchase/search_suppliers/?q=${encodeURIComponent(query)}`,
    method: 'get'
  })
}

// 获取协作者信息
export function GetCollaborators(id) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/collaborators/`,
    method: 'get'
  })
}

// 添加协作者
export function AddCollaborators(id, data) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/collaborators/`,
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 移除协作者
export function RemoveCollaborators(id, data) {
  return request({
    url: `/crm/api/crmorderpurchase/${id}/collaborators/`,
    headers: { 'content-type': 'application/json' },
    method: 'delete',
    data: data
  })
}

// 搜索项目用户
export function SearchProjectUsers(query) {
  return request({
    url: `/crm/api/crmorderpurchase/project_users/?keyword=${encodeURIComponent(query)}`,
    method: 'get'
  })
}
